package book.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import book.service.BookService;
import book.service.Library_cardService;
import book.service.impl.BookServiceImpl;
import book.service.impl.Library_cardServiceImpl;
import book.util.Library_card;

public class library_cardServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		//PrintWriter out = response.getWriter();
		HttpSession session=request.getSession();
		String opr=request.getParameter("opr");
		Library_cardService as=new Library_cardServiceImpl();
		
	 if("findAlllibrary_card".equals(opr)){
		 List<Library_card> lylist=as.findLibrary_cardAll();
		 session.setAttribute("lylist",lylist);
		 response.sendRedirect("jsp/bookyue.jsp");
	 }else if("del".equals(opr)){
		 Integer card_ID=Integer.parseInt(request.getParameter("card_ID"));
		 int num=as.deletefrom(card_ID);
		 if(num>0){
			 response.sendRedirect("library_cardServlet?opr=findAlllibrary_card");
			 
		 }else{
				System.out.println("失败");  
	 }
	}else if("add".equals(opr)){
		
		Integer card_ID=Integer.parseInt(request.getParameter("card_ID"));
		String Username=request.getParameter("Username");
		String Company=request.getParameter("Company");
		String Type=request.getParameter("Type");
		String title=request.getParameter("title");
		Library_card a=new Library_card(card_ID,Username,Company,Type);
		int num=as.insertinto(a);
		if(num>0){
			 response.sendRedirect("library_cardServlet?opr=findAlllibrary_card");
			 
		 }else{
				System.out.println("失败");
	}

	}else if("upd".equals(opr)){
		Integer card_ID=Integer.parseInt(request.getParameter("card_ID"));
		String Username=request.getParameter("Username");
		String Company=request.getParameter("Company");
		String Type=request.getParameter("Type");
		Library_card a=new Library_card(card_ID,Username,Company,Type);
		int num=as.insertinto(a);
		if(num>0){
			 response.sendRedirect("library_cardServlet?opr=findAlllibrary_card");
			 
		 }else{
				System.out.println("失败");
	}
}
}
}